


-- 由于Ceph无法接受GB2312编码的URL，所以在处理STA之前，将url进行转码
-- GB2312 to utf-8
-- by hongkui.an 2015.02.27




local _M = { _VERSION = "0.0.1" }
local utf8 = require "util.utf8"
local global = require "global"

function _M.client_before_req_filter()
	local str = ngx.unescape_uri(ngx.var.request_uri)
	local ret = utf8.check_utf8(str, #str)

	if not ret then
		local iconv = require("iconv")  
		--local cd = iconv.new("gb2312", "utf8")
		local cd = iconv.new("utf8", "gb2312")
		str, err = cd:iconv(str)
		global.sta.uri = ngx.var.http_host .. ngx.escape_uri(str)
	end
end

return _M
